include("shared.lua")

function ENT:Draw()
	self:DrawModel()
end

function openATMmenu(balance)
	atmMenu = vgui.Create( "DFrame" )
	atmMenu:SetSize( 150, 200 )
	atmMenu:SetPos( ScrW() / 2 - atmMenu:GetWide()/2, ScrH() / 2 - atmMenu:GetTall()/2 )
	atmMenu:SetTitle( "ATM" ) //Feel free to change the name
	atmMenu:SetVisible( true )
	atmMenu:SetDraggable( false )
	atmMenu:ShowCloseButton( true )
	atmMenu:MakePopup()

	balanceText = vgui.Create( "DLabel", atmMenu )
	balanceText:SetColor( Color( 255, 255, 255, 255 ) )
	balanceText:SetFont( "TabLarge" )
	balanceText:SetText( "Balance: " .. balance)
	balanceText:SizeToContents()
	balanceText:SetPos( atmMenu:GetWide()/2-balanceText:GetWide()/2, 180  )

	local withDrawText = vgui.Create( "DLabel", atmMenu )
	withDrawText:SetColor( Color( 255, 255, 255, 255 ) )
	withDrawText:SetFont( "TabLarge" )
	withDrawText:SetText( "Withdraw:" )
	withDrawText:SizeToContents()
	withDrawText:SetPos( atmMenu:GetWide()/2-withDrawText:GetWide()/2, 55  )

	withdraw = vgui.Create( "DTextEntry", atmMenu )
	withdraw:SetSize( 70, 15 ) //SetSize( 33.5, 15 )
	withdraw:SetPos( atmMenu:GetWide()/2-withdraw:GetWide()/2, 70 )
	withdraw:RequestFocus()

	local cur1 = vgui.Create( "DLabel", atmMenu )
	cur1:SetColor( Color( 255, 255, 255, 255 ) )
	cur1:SetFont( "TabLarge" )
	cur1:SetText( "$" )
	cur1:SizeToContents()
	cur1:SetPos( atmMenu:GetWide()/2-withdraw:GetWide()/2-cur1:GetWide()-2, 70  )

	local acceptWithdraw = vgui.Create( "DButton", atmMenu )
	acceptWithdraw:SetSize( 55, 15 )
	acceptWithdraw:SetPos( atmMenu:GetWide()/2-acceptWithdraw:GetWide()/2, 85 )
	acceptWithdraw:SetText( "Accept" )
	acceptWithdraw.DoClick = function()
		if not withdraw:GetValue() and isnumber(withdraw:GetValue()) then return end

			net.Start("withdraw")
				net.WriteString(tostring(math.Round(withdraw:GetValue())))
			net.SendToServer()
	end

	local depositText = vgui.Create( "DLabel", atmMenu )
	depositText:SetColor( Color( 255, 255, 255, 255 ) )
	depositText:SetFont( "TabLarge" )
	depositText:SetText( "Deposit:" )
	depositText:SizeToContents()
	depositText:SetPos( atmMenu:GetWide()/2-depositText:GetWide()/2, 115  )

	deposit = vgui.Create( "DTextEntry", atmMenu )
	deposit:SetSize( 70, 15 ) //SetSize( 33.5, 15 )
	deposit:SetPos( atmMenu:GetWide()/2-deposit:GetWide()/2, 130 )
	deposit:RequestFocus()

	local cur2 = vgui.Create( "DLabel", atmMenu )
	cur2:SetColor( Color( 255, 255, 255, 255 ) )
	cur2:SetFont( "TabLarge" )
	cur2:SetText( "$" )
	cur2:SizeToContents()
	cur2:SetPos( atmMenu:GetWide()/2-deposit:GetWide()/2-cur2:GetWide()-2, 130  )

	local acceptWithdraw = vgui.Create( "DButton", atmMenu )
	acceptWithdraw:SetSize( 55, 15 )
	acceptWithdraw:SetPos( atmMenu:GetWide()/2-acceptWithdraw:GetWide()/2, 145 )
	acceptWithdraw:SetText( "Accept" )
	acceptWithdraw.DoClick = function()
		if not deposit:GetValue() and isnumber(deposit:GetValue()) then return end

			net.Start("deposit")
				net.WriteString(tostring(math.Round(deposit:GetValue())))
			net.SendToServer()
	end
end

net.Receive("openATMmenu",function() openATMmenu(tonumber(net.ReadString())) end)

net.Receive("balanceUpdate",function() balanceText:SetText("Balance: " .. net.ReadString()) balanceText:SizeToContents() end)